
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/05/2013 23:48:17
-- Generated from EDMX file: E:\Downloads\Project1\Project1\models\FoulekModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [foulekbeta];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_GameRule_Game]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GameRule] DROP CONSTRAINT [FK_GameRule_Game];
GO
IF OBJECT_ID(N'[dbo].[FK_GameRule_Rule]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GameRule] DROP CONSTRAINT [FK_GameRule_Rule];
GO
IF OBJECT_ID(N'[dbo].[FK_SessionGame]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rooms] DROP CONSTRAINT [FK_SessionGame];
GO
IF OBJECT_ID(N'[dbo].[FK_UserUserSession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserInRooms] DROP CONSTRAINT [FK_UserUserSession];
GO
IF OBJECT_ID(N'[dbo].[FK_SessionUserSession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserInRooms] DROP CONSTRAINT [FK_SessionUserSession];
GO
IF OBJECT_ID(N'[dbo].[FK_LanguageUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users] DROP CONSTRAINT [FK_LanguageUser];
GO
IF OBJECT_ID(N'[dbo].[FK_RoomRound]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rounds] DROP CONSTRAINT [FK_RoomRound];
GO
IF OBJECT_ID(N'[dbo].[FK_RoundQuestion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rounds] DROP CONSTRAINT [FK_RoundQuestion];
GO
IF OBJECT_ID(N'[dbo].[FK_WinnerRound]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Winners] DROP CONSTRAINT [FK_WinnerRound];
GO
IF OBJECT_ID(N'[dbo].[FK_WinnerUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Winners] DROP CONSTRAINT [FK_WinnerUser];
GO
IF OBJECT_ID(N'[dbo].[FK_AchievementLanguage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Achievements] DROP CONSTRAINT [FK_AchievementLanguage];
GO
IF OBJECT_ID(N'[dbo].[FK_CompletedAchievementUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompletedAchievements] DROP CONSTRAINT [FK_CompletedAchievementUser];
GO
IF OBJECT_ID(N'[dbo].[FK_CompletedAchievementAchievement]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompletedAchievements] DROP CONSTRAINT [FK_CompletedAchievementAchievement];
GO
IF OBJECT_ID(N'[dbo].[FK_WinnerQuestion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Winners] DROP CONSTRAINT [FK_WinnerQuestion];
GO
IF OBJECT_ID(N'[dbo].[FK_RoundUser_Round]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoundUser] DROP CONSTRAINT [FK_RoundUser_Round];
GO
IF OBJECT_ID(N'[dbo].[FK_RoundUser_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoundUser] DROP CONSTRAINT [FK_RoundUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_CreditsUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Credits] DROP CONSTRAINT [FK_CreditsUser];
GO
IF OBJECT_ID(N'[dbo].[FK_CreditsTransaction]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Transactions] DROP CONSTRAINT [FK_CreditsTransaction];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoryQuestion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Questions] DROP CONSTRAINT [FK_CategoryQuestion];
GO
IF OBJECT_ID(N'[dbo].[FK_TextLanguage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Questions_Text] DROP CONSTRAINT [FK_TextLanguage];
GO
IF OBJECT_ID(N'[dbo].[FK_Text_inherits_Question]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Questions_Text] DROP CONSTRAINT [FK_Text_inherits_Question];
GO
IF OBJECT_ID(N'[dbo].[FK_FoulekRule_inherits_Rule]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rules_FoulekRule] DROP CONSTRAINT [FK_FoulekRule_inherits_Rule];
GO
IF OBJECT_ID(N'[dbo].[FK_Logo_inherits_Question]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Questions_Logo] DROP CONSTRAINT [FK_Logo_inherits_Question];
GO
IF OBJECT_ID(N'[dbo].[FK_Audio_inherits_Question]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Questions_Audio] DROP CONSTRAINT [FK_Audio_inherits_Question];
GO
IF OBJECT_ID(N'[dbo].[FK_Video_inherits_Question]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Questions_Video] DROP CONSTRAINT [FK_Video_inherits_Question];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Games]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Games];
GO
IF OBJECT_ID(N'[dbo].[Rules]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rules];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[Rooms]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rooms];
GO
IF OBJECT_ID(N'[dbo].[UserInRooms]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserInRooms];
GO
IF OBJECT_ID(N'[dbo].[Questions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Questions];
GO
IF OBJECT_ID(N'[dbo].[Languages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Languages];
GO
IF OBJECT_ID(N'[dbo].[Achievements]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Achievements];
GO
IF OBJECT_ID(N'[dbo].[Rounds]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rounds];
GO
IF OBJECT_ID(N'[dbo].[Winners]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Winners];
GO
IF OBJECT_ID(N'[dbo].[CompletedAchievements]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompletedAchievements];
GO
IF OBJECT_ID(N'[dbo].[Credits]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Credits];
GO
IF OBJECT_ID(N'[dbo].[Transactions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Transactions];
GO
IF OBJECT_ID(N'[dbo].[Categories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Categories];
GO
IF OBJECT_ID(N'[dbo].[Questions_Text]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Questions_Text];
GO
IF OBJECT_ID(N'[dbo].[Rules_FoulekRule]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rules_FoulekRule];
GO
IF OBJECT_ID(N'[dbo].[Questions_Logo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Questions_Logo];
GO
IF OBJECT_ID(N'[dbo].[Questions_Audio]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Questions_Audio];
GO
IF OBJECT_ID(N'[dbo].[Questions_Video]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Questions_Video];
GO
IF OBJECT_ID(N'[dbo].[GameRule]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GameRule];
GO
IF OBJECT_ID(N'[dbo].[RoundUser]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoundUser];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Games'
CREATE TABLE [dbo].[Games] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Type] int  NOT NULL,
    [Logo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Rules'
CREATE TABLE [dbo].[Rules] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [FirstName] nvarchar(max)  NULL,
    [LastName] nvarchar(max)  NULL,
    [Birthday] datetime  NOT NULL,
    [IsValidated] bit  NOT NULL,
    [Status] int  NOT NULL,
    [LanguageId] int  NOT NULL
);
GO

-- Creating table 'Rooms'
CREATE TABLE [dbo].[Rooms] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Buyin] decimal(18,0)  NOT NULL,
    [MaxPlayers] int  NOT NULL,
    [GameId] int  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [Status] int  NOT NULL,
    [EndDate] datetime  NULL,
    [MoneyType] int  NOT NULL
);
GO

-- Creating table 'UserInRooms'
CREATE TABLE [dbo].[UserInRooms] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [RoomId] int  NOT NULL,
    [JoinedDate] datetime  NOT NULL,
    [LeftDate] datetime  NULL
);
GO

-- Creating table 'Questions'
CREATE TABLE [dbo].[Questions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CategoryId] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Weight] int  NOT NULL
);
GO

-- Creating table 'Languages'
CREATE TABLE [dbo].[Languages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CultureName] nvarchar(max)  NOT NULL,
    [DisplayName] nvarchar(max)  NOT NULL,
    [NativeName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Achievements'
CREATE TABLE [dbo].[Achievements] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [LanguageId] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Rounds'
CREATE TABLE [dbo].[Rounds] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RoomId] int  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [EndDate] datetime  NULL,
    [Question_Id] int  NOT NULL
);
GO

-- Creating table 'Winners'
CREATE TABLE [dbo].[Winners] (
    [RoundId] int  NOT NULL,
    [UserId] int  NOT NULL,
    [AnswerDate] datetime  NOT NULL,
    [QuestionId] int  NOT NULL
);
GO

-- Creating table 'CompletedAchievements'
CREATE TABLE [dbo].[CompletedAchievements] (
    [UserId] int  NOT NULL,
    [AchievementId] int  NOT NULL,
    [Date] datetime  NOT NULL
);
GO

-- Creating table 'Credits'
CREATE TABLE [dbo].[Credits] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RealAmount] decimal(18,0)  NOT NULL,
    [VirtualAmount] decimal(18,0)  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'Transactions'
CREATE TABLE [dbo].[Transactions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CreditsId] int  NOT NULL,
    [RealAmount] decimal(18,0)  NOT NULL,
    [VirtualAmount] decimal(18,0)  NOT NULL,
    [Date] datetime  NOT NULL
);
GO

-- Creating table 'Categories'
CREATE TABLE [dbo].[Categories] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Questions_Text'
CREATE TABLE [dbo].[Questions_Text] (
    [Title] nvarchar(max)  NOT NULL,
    [Answer] nvarchar(max)  NOT NULL,
    [LanguageId] int  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Rules_FoulekRule'
CREATE TABLE [dbo].[Rules_FoulekRule] (
    [Commission] decimal(18,0)  NOT NULL,
    [Winners] decimal(18,0)  NOT NULL,
    [RoundTime] time  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Questions_Logo'
CREATE TABLE [dbo].[Questions_Logo] (
    [URL] nvarchar(max)  NOT NULL,
    [Answer] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Questions_Audio'
CREATE TABLE [dbo].[Questions_Audio] (
    [URL] nvarchar(max)  NOT NULL,
    [Answer] nvarchar(max)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'Questions_Video'
CREATE TABLE [dbo].[Questions_Video] (
    [URL] nvarchar(max)  NOT NULL,
    [Answer] nvarchar(max)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'GameRule'
CREATE TABLE [dbo].[GameRule] (
    [Games_Id] int  NOT NULL,
    [Rules_Id] int  NOT NULL
);
GO

-- Creating table 'RoundUser'
CREATE TABLE [dbo].[RoundUser] (
    [RoundUser_User_Id] int  NOT NULL,
    [Users_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Games'
ALTER TABLE [dbo].[Games]
ADD CONSTRAINT [PK_Games]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Rules'
ALTER TABLE [dbo].[Rules]
ADD CONSTRAINT [PK_Rules]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Rooms'
ALTER TABLE [dbo].[Rooms]
ADD CONSTRAINT [PK_Rooms]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserInRooms'
ALTER TABLE [dbo].[UserInRooms]
ADD CONSTRAINT [PK_UserInRooms]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Questions'
ALTER TABLE [dbo].[Questions]
ADD CONSTRAINT [PK_Questions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Languages'
ALTER TABLE [dbo].[Languages]
ADD CONSTRAINT [PK_Languages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Achievements'
ALTER TABLE [dbo].[Achievements]
ADD CONSTRAINT [PK_Achievements]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Rounds'
ALTER TABLE [dbo].[Rounds]
ADD CONSTRAINT [PK_Rounds]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [RoundId], [UserId] in table 'Winners'
ALTER TABLE [dbo].[Winners]
ADD CONSTRAINT [PK_Winners]
    PRIMARY KEY CLUSTERED ([RoundId], [UserId] ASC);
GO

-- Creating primary key on [UserId], [AchievementId] in table 'CompletedAchievements'
ALTER TABLE [dbo].[CompletedAchievements]
ADD CONSTRAINT [PK_CompletedAchievements]
    PRIMARY KEY CLUSTERED ([UserId], [AchievementId] ASC);
GO

-- Creating primary key on [Id] in table 'Credits'
ALTER TABLE [dbo].[Credits]
ADD CONSTRAINT [PK_Credits]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Transactions'
ALTER TABLE [dbo].[Transactions]
ADD CONSTRAINT [PK_Transactions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [PK_Categories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Questions_Text'
ALTER TABLE [dbo].[Questions_Text]
ADD CONSTRAINT [PK_Questions_Text]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Rules_FoulekRule'
ALTER TABLE [dbo].[Rules_FoulekRule]
ADD CONSTRAINT [PK_Rules_FoulekRule]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Questions_Logo'
ALTER TABLE [dbo].[Questions_Logo]
ADD CONSTRAINT [PK_Questions_Logo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Questions_Audio'
ALTER TABLE [dbo].[Questions_Audio]
ADD CONSTRAINT [PK_Questions_Audio]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Questions_Video'
ALTER TABLE [dbo].[Questions_Video]
ADD CONSTRAINT [PK_Questions_Video]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Games_Id], [Rules_Id] in table 'GameRule'
ALTER TABLE [dbo].[GameRule]
ADD CONSTRAINT [PK_GameRule]
    PRIMARY KEY NONCLUSTERED ([Games_Id], [Rules_Id] ASC);
GO

-- Creating primary key on [RoundUser_User_Id], [Users_Id] in table 'RoundUser'
ALTER TABLE [dbo].[RoundUser]
ADD CONSTRAINT [PK_RoundUser]
    PRIMARY KEY NONCLUSTERED ([RoundUser_User_Id], [Users_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Games_Id] in table 'GameRule'
ALTER TABLE [dbo].[GameRule]
ADD CONSTRAINT [FK_GameRule_Game]
    FOREIGN KEY ([Games_Id])
    REFERENCES [dbo].[Games]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Rules_Id] in table 'GameRule'
ALTER TABLE [dbo].[GameRule]
ADD CONSTRAINT [FK_GameRule_Rule]
    FOREIGN KEY ([Rules_Id])
    REFERENCES [dbo].[Rules]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GameRule_Rule'
CREATE INDEX [IX_FK_GameRule_Rule]
ON [dbo].[GameRule]
    ([Rules_Id]);
GO

-- Creating foreign key on [GameId] in table 'Rooms'
ALTER TABLE [dbo].[Rooms]
ADD CONSTRAINT [FK_SessionGame]
    FOREIGN KEY ([GameId])
    REFERENCES [dbo].[Games]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SessionGame'
CREATE INDEX [IX_FK_SessionGame]
ON [dbo].[Rooms]
    ([GameId]);
GO

-- Creating foreign key on [UserId] in table 'UserInRooms'
ALTER TABLE [dbo].[UserInRooms]
ADD CONSTRAINT [FK_UserUserSession]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserUserSession'
CREATE INDEX [IX_FK_UserUserSession]
ON [dbo].[UserInRooms]
    ([UserId]);
GO

-- Creating foreign key on [RoomId] in table 'UserInRooms'
ALTER TABLE [dbo].[UserInRooms]
ADD CONSTRAINT [FK_SessionUserSession]
    FOREIGN KEY ([RoomId])
    REFERENCES [dbo].[Rooms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SessionUserSession'
CREATE INDEX [IX_FK_SessionUserSession]
ON [dbo].[UserInRooms]
    ([RoomId]);
GO

-- Creating foreign key on [LanguageId] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [FK_LanguageUser]
    FOREIGN KEY ([LanguageId])
    REFERENCES [dbo].[Languages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LanguageUser'
CREATE INDEX [IX_FK_LanguageUser]
ON [dbo].[Users]
    ([LanguageId]);
GO

-- Creating foreign key on [RoomId] in table 'Rounds'
ALTER TABLE [dbo].[Rounds]
ADD CONSTRAINT [FK_RoomRound]
    FOREIGN KEY ([RoomId])
    REFERENCES [dbo].[Rooms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoomRound'
CREATE INDEX [IX_FK_RoomRound]
ON [dbo].[Rounds]
    ([RoomId]);
GO

-- Creating foreign key on [Question_Id] in table 'Rounds'
ALTER TABLE [dbo].[Rounds]
ADD CONSTRAINT [FK_RoundQuestion]
    FOREIGN KEY ([Question_Id])
    REFERENCES [dbo].[Questions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoundQuestion'
CREATE INDEX [IX_FK_RoundQuestion]
ON [dbo].[Rounds]
    ([Question_Id]);
GO

-- Creating foreign key on [RoundId] in table 'Winners'
ALTER TABLE [dbo].[Winners]
ADD CONSTRAINT [FK_WinnerRound]
    FOREIGN KEY ([RoundId])
    REFERENCES [dbo].[Rounds]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UserId] in table 'Winners'
ALTER TABLE [dbo].[Winners]
ADD CONSTRAINT [FK_WinnerUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WinnerUser'
CREATE INDEX [IX_FK_WinnerUser]
ON [dbo].[Winners]
    ([UserId]);
GO

-- Creating foreign key on [LanguageId] in table 'Achievements'
ALTER TABLE [dbo].[Achievements]
ADD CONSTRAINT [FK_AchievementLanguage]
    FOREIGN KEY ([LanguageId])
    REFERENCES [dbo].[Languages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AchievementLanguage'
CREATE INDEX [IX_FK_AchievementLanguage]
ON [dbo].[Achievements]
    ([LanguageId]);
GO

-- Creating foreign key on [UserId] in table 'CompletedAchievements'
ALTER TABLE [dbo].[CompletedAchievements]
ADD CONSTRAINT [FK_CompletedAchievementUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [AchievementId] in table 'CompletedAchievements'
ALTER TABLE [dbo].[CompletedAchievements]
ADD CONSTRAINT [FK_CompletedAchievementAchievement]
    FOREIGN KEY ([AchievementId])
    REFERENCES [dbo].[Achievements]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CompletedAchievementAchievement'
CREATE INDEX [IX_FK_CompletedAchievementAchievement]
ON [dbo].[CompletedAchievements]
    ([AchievementId]);
GO

-- Creating foreign key on [QuestionId] in table 'Winners'
ALTER TABLE [dbo].[Winners]
ADD CONSTRAINT [FK_WinnerQuestion]
    FOREIGN KEY ([QuestionId])
    REFERENCES [dbo].[Questions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WinnerQuestion'
CREATE INDEX [IX_FK_WinnerQuestion]
ON [dbo].[Winners]
    ([QuestionId]);
GO

-- Creating foreign key on [RoundUser_User_Id] in table 'RoundUser'
ALTER TABLE [dbo].[RoundUser]
ADD CONSTRAINT [FK_RoundUser_Round]
    FOREIGN KEY ([RoundUser_User_Id])
    REFERENCES [dbo].[Rounds]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Users_Id] in table 'RoundUser'
ALTER TABLE [dbo].[RoundUser]
ADD CONSTRAINT [FK_RoundUser_User]
    FOREIGN KEY ([Users_Id])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoundUser_User'
CREATE INDEX [IX_FK_RoundUser_User]
ON [dbo].[RoundUser]
    ([Users_Id]);
GO

-- Creating foreign key on [User_Id] in table 'Credits'
ALTER TABLE [dbo].[Credits]
ADD CONSTRAINT [FK_CreditsUser]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CreditsUser'
CREATE INDEX [IX_FK_CreditsUser]
ON [dbo].[Credits]
    ([User_Id]);
GO

-- Creating foreign key on [CreditsId] in table 'Transactions'
ALTER TABLE [dbo].[Transactions]
ADD CONSTRAINT [FK_CreditsTransaction]
    FOREIGN KEY ([CreditsId])
    REFERENCES [dbo].[Credits]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CreditsTransaction'
CREATE INDEX [IX_FK_CreditsTransaction]
ON [dbo].[Transactions]
    ([CreditsId]);
GO

-- Creating foreign key on [CategoryId] in table 'Questions'
ALTER TABLE [dbo].[Questions]
ADD CONSTRAINT [FK_CategoryQuestion]
    FOREIGN KEY ([CategoryId])
    REFERENCES [dbo].[Categories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryQuestion'
CREATE INDEX [IX_FK_CategoryQuestion]
ON [dbo].[Questions]
    ([CategoryId]);
GO

-- Creating foreign key on [LanguageId] in table 'Questions_Text'
ALTER TABLE [dbo].[Questions_Text]
ADD CONSTRAINT [FK_TextLanguage]
    FOREIGN KEY ([LanguageId])
    REFERENCES [dbo].[Languages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TextLanguage'
CREATE INDEX [IX_FK_TextLanguage]
ON [dbo].[Questions_Text]
    ([LanguageId]);
GO

-- Creating foreign key on [Id] in table 'Questions_Text'
ALTER TABLE [dbo].[Questions_Text]
ADD CONSTRAINT [FK_Text_inherits_Question]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Questions]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Rules_FoulekRule'
ALTER TABLE [dbo].[Rules_FoulekRule]
ADD CONSTRAINT [FK_FoulekRule_inherits_Rule]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Rules]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Questions_Logo'
ALTER TABLE [dbo].[Questions_Logo]
ADD CONSTRAINT [FK_Logo_inherits_Question]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Questions]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Questions_Audio'
ALTER TABLE [dbo].[Questions_Audio]
ADD CONSTRAINT [FK_Audio_inherits_Question]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Questions]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Questions_Video'
ALTER TABLE [dbo].[Questions_Video]
ADD CONSTRAINT [FK_Video_inherits_Question]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Questions]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------